﻿

<?php


$gameUrl=$_GET["gameUrl"];
$userId=$_GET["userId"];  
$gameName=$_GET["gameName"];
$picUrl=$_GET["picUrl"];
$gameDesc=$_GET["gameDesc"];

require('_config-rating.php'); // get the db connection info

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
}


$sql="SELECT gameId FROM games WHERE gameUrl = '".$gameUrl."'";
$result = mysql_query($sql,$con);

if ($result){//eger oyun game tablosunda varsa
	$gameId = $row["gameId"];
	$row = mysql_fetch_array($result);
	
	if ($row["gameId"]>0){//eger oyun game tablosunda varsa
		$gameId = $row["gameId"];
			$sql="INSERT INTO favorites (personId, gameId) VALUES ('$userId','$gameId')";
			if (!mysql_query($sql,$con))
			{
			  echo 0;
			}else echo 1;
		//}
	}else echo "gameId!>0";
}else echo "defasd";
mysql_close($con);


/*
if ($row["gameId"]>0){//eger oyun game tablosunda varsa
	$gameId = $row["gameId"];
	add2log($con,'test2');
	$sql="SELECT personId,gameId FROM favorites WHERE gameId = ".$gameId."";
	$result = mysql_query($sql,$con);
	$row = mysql_fetch_array($result);
	if ($row["personId"]>0){//eger oyun game tablosunda varsa
	
		$personId = $row["personId"];
		$gameId2 = $row["gameId"];
		
		if($personId!=$userId && $gameId2!=$gameId){
			
			$sql="INSERT INTO favorites (personId, gameId) VALUES ('$userId','$gameId')";
			if (!mysql_query($sql,$con))
			{
			  echo 0;
			}else echo 1;
		}else echo 1;
	}else{
		$sql="INSERT INTO favorites (personId, gameId) VALUES ('$userId','$gameId')";
		if (!mysql_query($sql,$con))
		{
		  echo 0;
		}else echo 1;
	}
}else echo 0;
/*
else {//eger oyun games tablosunda yoksa
	$sql="INSERT INTO games (picUrl, gameUrl, gameName,gameDesc) VALUES ('$picUrl','$gameUrl','$gameName','$gameDesc')";
	if (!mysql_query($sql,$con))
	{
		echo false;
	}else{
		$sql="SELECT * FROM games WHERE gameUrl = '".$gameUrl."'";
		$result = mysql_query($sql,$con);
		$row = mysql_fetch_array($result);
		if ($row["gameId"]>0){//eger oyun game tablosunda varsa
			$gameId = $row["gameId"];
			$sql="INSERT INTO favorites (personId, gameId) VALUES ('$userId','$gameId')";
		
			if (!mysql_query($sql,$con))
			{
			  echo false;
			}else echo true;
		}

	}

}*/

function add2log($con,$str){
	$logger = "insert into logger (Id, log) values (null,'$str' )";
	$result = mysql_query($logger,$con);
	//0$row = mysql_fetch_array($result);
	$err = mysql_error($con);
}
?>
